﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Model;
using System.Text;
using System.Collections.Generic;
public partial class Admin_AddProductAttribute : System.Web.UI.Page
{
    ProductAttributeBll proAttrBll = new ProductAttributeBll();
    AttributeBll atrBll = new AttributeBll();
    productBll pBll = new productBll();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["action"]!=null)
            {
                string action = Request.QueryString["action"].ToString().Trim();
                switch (action)
                {
                    case "insert":
                        Insert();
                        break;
                    case "load":
                        int id = Convert.ToInt32(Request.QueryString["pid"]);
                        load(id);
                        break;
                    default:
                        break;
                }
            }
        }
    }

    #region 下拉框
    public string attributeDp(string name)
    {
        int pid = Convert.ToInt32(Request.QueryString["pid"]);
        StringBuilder str = new StringBuilder();
        str.Append("<select name='selectDp' id='" + name + "' style='width:192px;'>");
        str.Append("<option value='0' selected='selected'>---顶级分类---</option>");
        IList<Attribute> attriList = atrBll.GetModel();
        foreach (Attribute atr in attriList)
        {
           
                str.AppendFormat("<option value='" + atr.attributeID + "'>{0}</option>", atr.attributeName);
          
        }
        str.Append("</select>");
        return str.ToString();
    }

    #endregion

    #region 加载产品id
    public void load(int id)
    {
        product product = pBll.GetModel(id);
        this.productName_txt.Value =product.productName;
        this.Hidden1.Value = product.productId.ToString();       
        Session["FCKeditor:UserFilesPath"] = "~/UploadFiles/productUpload/" + product.Productmodel;
    }
    #endregion

    #region 添加
    public void Insert()
    {
        int id = Convert.ToInt32(Request.QueryString["id"]);
        ProductAttribute proAttr = new ProductAttribute();
        proAttr.productID = id;
        proAttr.productAttributeUrl = Request.Form["content"].ToString();     
        proAttr.attributeID = Convert.ToInt32(Request.Form["selectDp"]);
        proAttr.productAttributeValue = Request.Form["productAttributeValue_txt"].ToString();
        if (proAttr.attributeID == 0)
        {
            Response.Write("请选择属性类型！");
            Response.End();
        }
        if (proAttr.productAttributeValue.Trim() == "")
        {
            Response.Write("请填写属性名称！");
            Response.End();
        }
        if (proAttr.productAttributeUrl.Trim()=="")
        {
            Response.Write("属性链接不能为空！");
            Response.End();
        }
        if (proAttrBll.Insert(proAttr))
        {
            Response.Write("1");
            Response.End();
        }  
    }
    #endregion
}
